﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.ApplicationModel.Bootstrap.Extensibility;
using System.Linq.Expressions;
using YasharEl.Infrastructure.ApplicationModel.Bootstrap.Syntax.Executables;
using YasharEl.Infrastructure.ApplicationModel.Bootstrap.Behavior;

namespace YasharEl.Infrastructure.ApplicationModel.Bootstrap.Syntax
{
    /// <summary>
    /// Factory which creates the set of executables.
    /// </summary>
    /// <typeparam name="TExtension">The type of the extension.</typeparam>
    public class ExecutableFactory<TExtension> : IExecutableFactory<TExtension>
        where TExtension : IBootstrappingExtension
    {
        /// <inheritdoc />
        public IExecutable<TExtension> CreateExecutable(Expression<Action> action)
        {
            return new ActionExecutable<TExtension>(action);
        }

        /// <inheritdoc />
        public IExecutable<TExtension> CreateExecutable<TContext>(Expression<Func<TContext>> initializer, Expression<Action<TExtension, TContext>> action, Action<IBehaviorAware<TExtension>, TContext> contextInterceptor)
        {
            return new ActionOnExtensionWithInitializerExecutable<TContext, TExtension>(initializer, action, contextInterceptor);
        }

        /// <inheritdoc />
        public IExecutable<TExtension> CreateExecutable(Expression<Action<TExtension>> action)
        {
            return new ActionOnExtensionExecutable<TExtension>(action);
        }
    }
}
